package model;

import java.util.Calendar;
import java.util.Date;

public class MyTokenClass {
    private static String systemId;
    private static String useId;
    private static String useType;
    private static String clientType;
    private static String accessToken;
    private static byte useClass;
    /**
     * 过期天数
     */
    private static byte days;

    private static Date validTime;

    /**
     * @return accessToken及一套字符串
     */
    public static String getAkfPara() {
        if (MyTokenClass.getValidTime() != null && MyTokenClass.getValidTime().compareTo(new Date()) > 0)
            return String.format("systemId=%s&useId=%s&useType=%s&clientType=%s&accessToken=%s"
                    , MyTokenClass.getSystemId()
                    , MyTokenClass.getUseId()
                    , MyTokenClass.getUseType()
                    , MyTokenClass.getClientType()
                    , MyTokenClass.getAccessToken()
            );
        else
            return null;
    }

    public static String getSystemId() {
        return systemId;
    }

    public static void setSystemId(String systemId) {
        MyTokenClass.systemId = systemId;
    }

    public static String getUseId() {
        return useId;
    }

    public static void setUseId(String useId) {
        MyTokenClass.useId = useId;
    }

    public static String getUseType() {
        return useType;
    }

    public static void setUseType(String useType) {
        MyTokenClass.useType = useType;
    }

    public static String getClientType() {
        return clientType;
    }

    public static void setClientType(String clientType) {
        MyTokenClass.clientType = clientType;
    }

    public static String getAccessToken() {
        return accessToken;
    }

    public static void setAccessToken(String accessToken) {
        MyTokenClass.accessToken = accessToken;
    }

    public static byte getUseClass() {
        return useClass;
    }

    public static void setUseClass(byte useClass) {
        MyTokenClass.useClass = useClass;
    }

    public static void setDays(byte days) {
        MyTokenClass.days = days;
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.add(Calendar.DAY_OF_MONTH, MyTokenClass.days);
        MyTokenClass.validTime = calendar.getTime();
    }

    public static Date getValidTime() {
        return validTime;
    }
}
